function k = findRadialCorrectionParam(pts1,imgSize,type)
%Pts1 --> points of a straight line (distorted)
%type, L1, L2, L3 (mean L n>=3)

if(strcmp(type,'L1'))
    x0 = imgSize(2)/2;
    y0 = imgSize(1)/2;

    N = size(pts1,1);
    M = zeros(N,3);
    b = zeros(N,1);

    for i=1:N
        P1 = [pts1(i,:) 1]; 
        r2 = (pts1(i,1)-x0)^2+(pts1(i,2)-y0)^2;
        %row = [r2 P];
        %row = [P1 P1*r2]; %Ma = b; b --> -r2
        row =  P1;
        M(i,:) = row;
        b(i,:) = r2;
    end
    L = pinv(transpose(M)*M)*transpose(M)*b;

    % [U,S,V] = svd(A);
    % L_vector = V(:,4);
    % L = L_vector(1:3)'./L_vector(4);

    lamda_inv = x0^2+y0^2+L(1)*x0+L(2)*y0+L(3);
    lamda = 1/lamda_inv;
    k = lamda;
end
if(strcmp(type,'L3'))
    x0 = imgSize(2)/2;
    y0 = imgSize(1)/2;

    N = size(pts1,1);
    n = size(pts1,3);
    
    Li = zeros(n,3);
    for i=1:n
        M = zeros(N,3);
        b = zeros(N,1);
        for j=1:N
            P1 = [pts1(i,:) 1]; 
            r2 = (pts1(i,1)-x0)^2+(pts1(i,2)-y0)^2;
            %row = [r2 P];
            %row = [P1 P1*r2]; %Ma = b; b --> -r2
            row =  P1;
            M(i,:) = row;
            b(i,:) = r2;
        end
        Li(i,:) = pinv(transpose(M)*M)*transpose(M)*b;
    end
    l = 0;
    for i=1:n
        for j=i+1:n
            l = l+1;
        end
    end
    C = zeros(l,3);
    count = 1;
    for i=1:n
        for j=i+1:n
            row = [Li(i,1)-Li(j,1) Li(i,2)-Li(j,2) Li(i,3)-Li(j,3)];
            C(count,:) = row;
            count = count+1;
        end
    end
    [U,S,V] = svd(C);
    center_vector = V(:,l);
    center = center_vector(1:2)'./center_vector(3);
    x0 = center(1);
    y0 = center(2);
    

    %find A B C and lamda...
    
    
    lamda_inv = x0^2+y0^2+L(1)*x0+L(2)*y0+L(3);
    lamda = 1/lamda_inv;
    k = lamda;
end